﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Entry;

namespace COFE.Core.Logger
{
    public class FileSystemEventLogPropertyProvider :
        ISecondaryPropertyProvider<IEventLog>
    {
        public object[] GetSupportedProperty(IEventLog sourceObj)
        {
            List<object> retVal = new List<object>();

            if (sourceObj is IEventLog<FileSystemEventArgsExA>)
            {
                retVal.Add(EventLogProperties.EventType);
                retVal.Add(EventLogProperties.IsFolder);
                retVal.Add(EventLogProperties.FullParseName);

                if (sourceObj is IEventLog<RenameEventArgsExA>)
                {
                    retVal.Add(EventLogProperties.OriginalParseName);
                }
            }

            return retVal.ToArray();
        }

        public bool IsPropertyReadOnly(IEventLog sourceObj, object property)
        {
            return true;
        }

        public PropertyPair GetProperty(IEventLog sourceObj, object property)
        {
            var fsiEvent = sourceObj.EventArgs as FileSystemEventArgsExA;

            if (fsiEvent != null)
                switch ((int)property)
                {
                    case (int)EventLogProperties.EventType:
                        return new PropertyPair(property, fsiEvent.ChangeType.ToString());
                    case (int)EventLogProperties.IsFolder:
                        return new PropertyPair(property, fsiEvent.IsFolder);
                    case (int)EventLogProperties.FullParseName:
                        return new PropertyPair(property, fsiEvent.ParsePath);
                    case (int)EventLogProperties.OriginalParseName:
                        var renameEvent = fsiEvent as RenameEventArgsExA;
                        if (renameEvent != null)
                            return new PropertyPair(property, renameEvent.OldParsePath);
                        break;
                }

            throw new NotSupportedException();
        }

        public void SetProperty(IEventLog sourceObj, object property, object value)
        {
            throw new NotSupportedException();
        }
    }
}
